#!/bin/bash

function meson_bld() {
	echo "Clean install directory!"
	rm -fr build work $RTE_TARGET

	meson --prefix=/$RTE_TARGET build
}

function ninja_build() {
	echo "Do Ninja in build directory"

	ninja -C build

	if [[ $? -ne 0 ]]; then
		echo "Build failed!!!"
		return 1;
        fi
	return 0       
}

ninja_install() {
	echo "Do Ninja install to $RTE_SDK/$RTE_TARGET"

	DESTDIR=$RTE_SDK ninja -C build install > /dev/null

	if [[ $? -ne 0 ]]; then
		echo "Install failed!!"
	       return 1;
        fi
	touch $RTE_SDK/$RTE_TARGET/.config
	return 0       
}

if [ $# -gt 0 ]; then
	meson_bld
fi
ninja_build && ninja_install
